package cn.initcap.algorithm.lambda;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author initcap
 * @date Created in 3/2/19 8:22 PM.
 */
public class TestLambdaStreamFilter {

    public static void main(String[] args) {
        List<String> categoryList = new ArrayList<>(3);
        categoryList.add("maintence");
        categoryList.add("checkPlan");
        categoryList.add("upkeep");

        List<TicketTask> ticketTaskList = new ArrayList<>(58);

        String category = categoryList.get(0);
        for (int i = 0; i < 85; i++) {
            ticketTaskList.add(new TicketTask("name" + i, category));
        }
        category = categoryList.get(1);
        for (int i = 0; i < 15; i++) {
            ticketTaskList.add(new TicketTask("name" + i, category));
        }
        category = categoryList.get(2);
        for (int i = 0; i < 23; i++) {
            ticketTaskList.add(new TicketTask("name" + i, category));
        }

        Map<String, Long> map = new HashMap<>(categoryList.size());
        categoryList.forEach(c -> {
            long size = ticketTaskList.stream().filter(t -> t.getCategory().equals(c)).count();
            map.put(c, size);
        });

        System.out.println(map);
    }

}
